/**
 * 
 */
package com.aspire.android.heliar.ui;

import com.aspire.android.heliar.pub.PubManager;
import com.aspire.android.heliar.utils.ContextFactory;

import com.aspire.android.heliar.R;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;


/**
 * @author panglei
 * 
 */
public class UIManager {

	public static final String PUB_LIST_TITLE = "pubTitle";
	public static final String PUB_LIST_DESC = "pubDesc";
	public static final String PUB_LIST_COVER = "pubCover";

	public static final int PUB_IMAGE_WIDTH = 50;
	public static final int PUB_IMAGE_HEIGHT = 50;
	
	public static void prepareStartup() {
		Activity activity = (Activity)ContextFactory.getInstance();
		activity.setContentView(R.layout.pre_startup);
		
		new Thread(new Runnable() {

			@Override
			public void run() {
				PubManager.getInstance();
			}
			
		});
	}

/*	public static View getPubListView() {
//		ListView view = new ListView(ContextFactory.getInstance());
//		ImageListViewAdapter adapter = new ImageListViewAdapter(
//				ContextFactory.getInstance(), getPubList(),
//				R.layout.pub_list_row, new String[] { PUB_LIST_TITLE,
//						PUB_LIST_DESC, PUB_LIST_COVER }, new int[] {
//						R.id.pubTitle, R.id.pubDesc, R.id.pubCover });
//		view.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> adapter, View v,
//					int position, long id) {
//				Pub pub = PubManager.getInstance().get(position);
//				OneFramePubRender render = new OneFramePubRender();
//				SpannableStringBuilder content = render.render(pub);
//				Activity activity = (Activity) ContextFactory.getInstance();
//				activity.setContentView(R.layout.pub_content_render);
//
//				TextView textView = (TextView) activity
//						.findViewById(R.id.pubRender);
//				textView.setText(content);
//
//			}
//		});
//		view.setAdapter(adapter);
//		return view;
	}*/
	
/*	public static List<Map<String, Object>> getPubList() {
		List<Map<String, Object>> pubList = new LinkedList<Map<String, Object>>();

		Map<String, Pub> pubs = PubManager.getInstance().getPubList();
		Set<String> pubIds = pubs.keySet();
		for (String pubId : pubIds) {
			Pub pub = pubs.get(pubId);
			Map<String, Object> item = new HashMap<String, Object>();
			item.put(PUB_LIST_TITLE, pub.getTitle());

			Log.d(Heliar.LOG_TAG, "pub.getDesc() = " + pub.getDesc());
			item.put(PUB_LIST_DESC, pub.getDesc());

			if (pub.getCover() == null) {
				item.put(PUB_LIST_COVER, R.drawable.default_pub_icon);
			} else {
				item.put(PUB_LIST_COVER, resize(pub.getCover().getBitmap()));
			}

			pubList.add(item);
		}

		return pubList;
	}*/

	public static BitmapDrawable resize(Bitmap bitmap) {

		return new BitmapDrawable(Bitmap.createScaledBitmap(bitmap,
				PUB_IMAGE_WIDTH, PUB_IMAGE_HEIGHT, false));
	}
}
